home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 2003 August / MW 8 2003 CD1.iso / Inside Macworld / Product News / gimp-1.2.4.sit / gimp-1.2.4 / plug-ins / script-fu / scripts / beveled-button.scm < prev    next >
Encoding:
Text File  |  2003-05-19  |  4.9 KB  |  166 lines

  1. ; The GIMP -- an image manipulation program
  2. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3. ; Button00 --- create a simple beveled Web button
  4. ; Copyright (C) 1997 Federico Mena Quintero
  5. ; federico@nuclecu.unam.mx
  6. ; This program is free software; you can redistribute it and/or modify
  7. ; it under the terms of the GNU General Public License as published by
  8. ; the Free Software Foundation; either version 2 of the License, or
  9. ; (at your option) any later version.
  10. ; This program is distributed in the hope that it will be useful,
  11. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. ; GNU General Public License for more details.
  14. ; You should have received a copy of the GNU General Public License
  15. ; along with this program; if not, write to the Free Software
  16. ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. ; ************************************************************************
  18. ; Changed on Feb 4, 1999 by Piet van Oostrum <piet@cs.uu.nl>
  19. ; For use with GIMP 1.1.
  20. ; All calls to gimp-text-* have been converted to use the *-fontname form.
  21. ; The corresponding parameters have been replaced by an SF-FONT parameter.
  22. ; ************************************************************************
  23.  
  24.  
  25. (define (text-width extents)
  26.   (car extents))
  27.  
  28. (define (text-height extents)
  29.   (cadr extents))
  30.  
  31. (define (text-ascent extents)
  32.   (caddr extents))
  33.  
  34. (define (text-descent extents)
  35.   (cadr (cddr extents)))
  36.  
  37. (define (blend-bumpmap img drawable x1 y1 x2 y2)
  38.   (gimp-blend drawable
  39.           FG-BG-RGB
  40.           DARKEN-ONLY
  41.           LINEAR
  42.           100
  43.           0
  44.           REPEAT-NONE
  45.           FALSE
  46.           0
  47.           0
  48.           x1
  49.           y1
  50.           x2
  51.           y2))
  52.  
  53. (define (script-fu-button00 text
  54.                 size
  55.                 font
  56.                 ul-color
  57.                 lr-color
  58.                 text-color
  59.                 padding
  60.                 bevel-width
  61.                 pressed)
  62.   (let* ((old-fg-color (car (gimp-palette-get-foreground)))
  63.      (old-bg-color (car (gimp-palette-get-background)))
  64.      
  65.      (text-extents (gimp-text-get-extents-fontname text
  66.                           size
  67.                           PIXELS
  68.                           font))
  69.      (ascent (text-ascent text-extents))
  70.      (descent (text-descent text-extents))
  71.      
  72.      (img-width (+ (* 2 (+ padding bevel-width))
  73.                (text-width text-extents)))
  74.      (img-height (+ (* 2 (+ padding bevel-width))
  75.             (+ ascent descent)))
  76.  
  77.      (img (car (gimp-image-new img-width img-height RGB)))
  78.  
  79.      (bumpmap (car (gimp-layer-new img img-width img-height RGBA_IMAGE "Bumpmap" 100 NORMAL)))
  80.      (gradient (car (gimp-layer-new img img-width img-height RGBA_IMAGE "Gradient" 100 NORMAL))))
  81.  
  82.     (gimp-image-undo-disable img)
  83.  
  84.     ; Create bumpmap layer
  85.     
  86.     (gimp-image-add-layer img bumpmap -1)
  87.     (gimp-palette-set-foreground '(0 0 0))
  88.     (gimp-palette-set-background '(255 255 255))
  89.     (gimp-edit-fill bumpmap BG-IMAGE-FILL)
  90.  
  91.     (gimp-rect-select img 0 0 bevel-width img-height REPLACE FALSE 0)
  92.     (blend-bumpmap img bumpmap 0 0 (- bevel-width 1) 0)
  93.  
  94.     (gimp-rect-select img 0 0 img-width bevel-width REPLACE FALSE 0)
  95.     (blend-bumpmap img bumpmap 0 0 0 (- bevel-width 1))
  96.  
  97.     (gimp-rect-select img (- img-width bevel-width) 0 bevel-width img-height REPLACE FALSE 0)
  98.     (blend-bumpmap img bumpmap (- img-width 1) 0 (- img-width bevel-width) 0)
  99.  
  100.     (gimp-rect-select img 0 (- img-height bevel-width) img-width bevel-width REPLACE FALSE 0)
  101.     (blend-bumpmap img bumpmap 0 (- img-height 1) 0 (- img-height bevel-width))
  102.  
  103.     (gimp-selection-none img)
  104.  
  105.     ; Create gradient layer
  106.  
  107.     (gimp-image-add-layer img gradient -1)
  108.     (gimp-palette-set-foreground ul-color)
  109.     (gimp-palette-set-background lr-color)
  110.     (gimp-blend gradient
  111.         FG-BG-RGB
  112.         NORMAL
  113.         LINEAR
  114.         100
  115.         0
  116.         REPEAT-NONE
  117.         FALSE
  118.         0
  119.         0
  120.         0
  121.         0
  122.         (- img-width 1)
  123.         (- img-height 1))
  124.  
  125.     (plug-in-bump-map 1 img gradient bumpmap 135 45 bevel-width 0 0 0 0 TRUE pressed 0)
  126.  
  127.     ; Create text layer
  128.  
  129.     (gimp-palette-set-foreground text-color)
  130.     (let ((textl (car (gimp-text-fontname
  131.                img -1 0 0 text 0 TRUE size PIXELS font))))
  132.       (gimp-layer-set-offsets textl
  133.                   (+ bevel-width padding)
  134.                   (+ bevel-width padding descent)))
  135.  
  136.     ; Done
  137.  
  138.     (gimp-selection-none img)
  139.     (gimp-palette-set-foreground old-fg-color)
  140.     (gimp-palette-set-background old-bg-color)
  141.     (gimp-image-undo-enable img)
  142.     (gimp-display-new img)))
  143.  
  144. ; Register!
  145.  
  146. (script-fu-register "script-fu-button00"
  147.             _"<Toolbox>/Xtns/Script-Fu/Buttons/Simple Beveled Button..."
  148.             "Simple beveled button"
  149.             "Federico Mena Quintero"
  150.             "Federico Mena Quintero"
  151.             "June 1997"
  152.             ""
  153.             SF-STRING     _"Text" "Hello world!"
  154.             SF-ADJUSTMENT _"Font Size (pixels)" '(16 2 100 1 1 0 1)
  155.             SF-FONT       _"Font" "-*-helvetica-*-r-*-*-16-*-*-*-p-*-*-*"
  156.             SF-COLOR      _"Upper-Left color" '(0 255 127)
  157.             SF-COLOR      _"Lower-Right color" '(0 127 255)
  158.             SF-COLOR      _"Text Color" '(0 0 0)
  159.             SF-ADJUSTMENT _"Padding" '(2 1 100 1 10 0 1)
  160.             SF-ADJUSTMENT _"Bevel Width" '(4 1 100 1 10 0 1)
  161.             SF-TOGGLE     _"Pressed" FALSE)
  162.